import java.util.Scanner;

public class Main {
    static class TreeNode {
        char val;
        TreeNode left;
        TreeNode right;

        TreeNode() {}

        TreeNode(char val) {
            this.val = val;
        }

    }

    //----------------------------------
    //二叉树的构建及遍历

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str=in.nextLine();

            TreeNode root = creattree(str);

            inorder(root);
        }
    }

    static int i=0;

    static TreeNode creattree(String str){
        TreeNode node=null;

        if(str.charAt(i)!='#'){
            node=new TreeNode(str.charAt(i++));
            node.left=creattree(str);
            node.right=creattree(str);
        }else{
            ++i;
        }

        return node;
    }

    static void inorder(TreeNode root){
        if(root==null)
            return;

        inorder(root.left);
        System.out.print(root.val+" ");
        inorder(root.right);
    }


    //----------------------------------
    //检查两棵树是否相同

    public boolean isSameTree1(TreeNode p, TreeNode q) {
        if(p==null&&q==null){
            return true;
        }
        if(p==null&&q!=null||p!=null&&q==null){
            return false;
        }
        if(p.val!=q.val){
            return false;
        }
        return isSameTree1(p.left,q.left)&&isSameTree1(p.right,q.right);
    }


    //----------------------------------
    //反转二叉树

    public TreeNode invertTree(TreeNode root) {
        if(root==null){
            return null;
        }
        TreeNode temp=root.left;
        root.left=root.right;
        root.right=temp;

        invertTree(root.left);
        invertTree(root.right);

        return root;
    }

    //----------------------------------
    //对称二叉树

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if(p==null&&q==null){
            return true;
        }
        if(p==null&&q!=null||p!=null&&q==null){
            return false;
        }
        if(p.val!=q.val){
            return false;
        }
        return isSameTree(p.left,q.right)&&isSameTree(p.right,q.left);
    }


    public boolean isSymmetric(TreeNode root) {
        if(root==null){
            return true;
        }
        if(root.left==null&&root.right!=null||root.left!=null&&root.right==null){
            return false;
        }
        if(root.left==null&&root.right==null){
            return true;
        }
        if(root.left.val!=root.right.val){
            return false;
        }
        return isSameTree(root.left.left,root.right.right)&&isSameTree(root.left.right,root.right.left);
    }

    //----------------------------------
    //另一棵树的子树

    public boolean isSameTree2(TreeNode p, TreeNode q) {
        if(p==null&&q==null){
            return true;
        }
        if(p == null || q == null){
            return false;
        }
        if(p.val!=q.val){
            return false;
        }
        return isSameTree2(p.left,q.left)&&isSameTree2(p.right,q.right);
    }

    public boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if(root==null&&subRoot==null){
            return true;
        }
        if(root!=null&&subRoot==null||root==null&&subRoot!=null){
            return false;
        }
        if(isSameTree(root,subRoot)){
            return true;
        }
        return isSubtree(root.left,subRoot)||isSubtree(root.right,subRoot);
    }

    //----------------------------------
    //判断一棵二叉树是否为平衡二叉树

    public int treeheigh(TreeNode root){
        if(root==null){
            return 0;
        }

        int lefthg=treeheigh(root.left);
        int righthg=treeheigh(root.right);

        if(lefthg>=0&&righthg>=0&&Math.abs(lefthg-righthg)<=1){
            return Math.max(lefthg,righthg)+1;
        }else{
            return -1;
        }

    }

    public boolean isBalanced(TreeNode root) {

        return treeheigh(root)>=0;
    }

}